/**
 * @BelongsProject : LeetCode
 * @Author : WXY
 * @CreateTime : 2022-12-07  23:14
 * @Description :剑指 Offer 16. 数值的整数次方
 * @Version : 1.0
 */

public class Num016_myPow {

    public static double myPow(double x, int n) {
        long N = n;
        return N >= 0 ? process(x, N) : 1.0 / process(x, N);
    }

    private static double process(double x, long n) {
        if (n == 0)return 1.0;
        double y = process(x, n / 2);
        return n % 2 == 0 ? y * y : x * y * y;
    }

    public static void main(String[] args) {
        double v = myPow(2, 3);
        System.out.println(v);
    }
}
